<template>
	<view class="economy-info">
		<view class="padding text-center">
			<view class="padding-xl radius shadow-blur bg-red margin-top bg-img" style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big91005.jpg);">
				<view>个人金币消费记录查询</view>
			</view>
		</view>
		<uni-list>
		    <uni-list-item v-for="v in pageList" :key="v.id"
				:title="'操作: ' + v.operation" 
				:note="'数量: ' + v.amount + ' 余额: ' + v.balance" 
				:rightText="v.date"></uni-list-item>
		</uni-list>
		<uni-pagination title="分页" show-icon="true" 
			:total="economyRecordList.length" 
			:pageSize="10"
			:current="curPage"
			@change="pageChange"></uni-pagination>
	</view>
</template>

<script>
	
	import {uniList} from '@dcloudio/uni-ui'
	import {uniListItem, uniPagination} from '@dcloudio/uni-ui'
	import ajax from '../../../Ajax/index.js'
	import common from '../../../common/index.js'
	export default {
		components: {
			uniList,
			uniListItem,
			uniPagination
		},
		data() {
			return {
				pageList: [],
				economyRecordList: [],
				curPage: 1,
			};
		},
		mounted() {
			this.getPlayerAllEconomyRecord()
		},
		methods: {
			getPlayerAllEconomyRecord() {
				let playerName = common.getCookie('playerName')
				if (!!!playerName) {
					uni.showToast({title: '请登录', icon: 'none'})
					return
				}
				let param = new URLSearchParams()
				param.append("playerName", playerName)
				ajax.post('economy/getPlayerAllEconomyRecord', param).then(res => {
					if (res.data.code == 200) {
						this.economyRecordList = res.data.list
						this.pageChange({current: 1})
					}
				})
			},
			pageChange(v) {
				this.curPage = v.current
				let index = (this.curPage - 1)
				if(index * 10 + 8 < this.economyRecordList.length) {
					this.pageList = this.economyRecordList.slice(index * 10, index * 10 + 10)
				} else {
					this.pageList = this.economyRecordList.slice(index * 10);
				}
			}
		}
	}
</script>

<style lang="scss">

</style>
